<template>
	<view class="container">
		<view class="box">
			<view class="user-box" :class="{'active': item.id == user.id}" v-for="item in list" :key="item.id" @click="selectItem(item)">
				<view class="image">
					<lazy-image :src="item.image"></lazy-image>
				</view>
				<!-- <image :src="$img_base_url(item.image)" mode="aspectFill"></image> -->
				<view class="info">
					<view class="l-1">
						<view class="left">
							<text class="name">{{ item.name }}</text>
							<!-- <text class="t">直营工程师</text> -->
						</view>
						<view class="right">
							<text>服务分：</text>{{ item.commentCount * 100 }}
						</view>
					</view>
					<view class="l-2">
						{{ item.age }}岁 | {{ item.city }}
					</view>
					<!-- <view class="l-3">
						<text>直营工程师</text><text>排烟省电</text>
					</view> -->
				</view>
			</view>
		</view>



		<view class="bottom-btn">
			<view class="b-btn">
				<view class="b">
					<button @click="confirm">确认</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getSkillList
	} from '../../utils/api/serviceApi';
	export default {
		data() {
			return {
				user: {},
				list: []
			};
		},
		onLoad() {
			this.getSkillList()
		},
		methods: {
			async getSkillList() {
				try {
					const select_city = uni.getStorageSync("select_city")
					console.log("select_city", )
					const value = select_city ? JSON.parse(select_city) : {}
					const res = await getSkillList({
						city: value.name,
						lat: value.lat,
						lng: value.lng,
						skill_cate_id: ""
					})
					console.log("获取服务人员列表 res", res)
					this.list = res.data
				} catch (e) {
					//TODO handle the exception
					console.log("获取服务人员列表失败", e)
				}
			},
			selectItem(item) {
				console.log("item", item)
				this.user = item
			},
			confirm() {
				if (!this.user.id) {
					uni.showToast({
						title: "请选择服务人员!",
						icon: "none"
					})
					return
				}
				uni.$emit("updateServiceUser", {data: this.user})
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		.tip {
			font-weight: bold;
			font-size: 32rpx;
			color: #E72A2A;
			line-height: 44rpx;
			padding: 22rpx;
			box-sizing: border-box;
			background: #FFEEEE;
		}

		.box {
			padding: 20rpx 22rpx;
			box-sizing: border-box;

			.title {
				font-weight: bold;
				font-size: 34rpx;
				color: #333333;
				line-height: 48rpx;
			}

			.user-box {
				display: flex;
				background-color: #FFFFFF;
				border-radius: 20rpx;
				margin-top: 20rpx;
				padding: 26rpx 14rpx 30rpx;
				box-sizing: border-box;

				.image {
					width: 134rpx;
					height: 134rpx;
					overflow: hidden;
					border-radius: 50%;
				}

				.info {
					width: calc(100% - 134rpx);
					padding-left: 20rpx;
					box-sizing: border-box;

					.l-1 {
						display: flex;
						align-items: center;
						justify-content: space-between;

						.left {
							display: flex;
							align-items: center;

							.name {
								font-weight: bold;
								font-size: 32rpx;
								color: #333333;
								line-height: 44rpx;
							}

							.t {
								padding: 4rpx 10rpx;
								box-sizing: border-box;
								background: #FF6602;
								border-radius: 6rpx;
								font-weight: 400;
								font-size: 20rpx;
								color: #FFFFFF;
								line-height: 28rpx;
								margin-left: 10rpx;

							}
						}

						.right {
							font-weight: bold;
							font-size: 36rpx;
							color: #E72A2A;
							line-height: 50rpx;

							text {
								font-size: 28rpx;
								color: #333333;
							}
						}
					}

					.l-2 {
						font-weight: bold;
						font-size: 28rpx;
						color: #333333;
						line-height: 40rpx;
						margin-top: 10rpx;
					}

					.l-3 {
						display: flex;
						flex-wrap: wrap;

						&>text {
							display: inline-block;
							padding: 4rpx 16rpx;
							box-sizing: border-box;
							border: 2rpx solid #0291FF;
							border-radius: 6rpx;
							font-weight: 400;
							font-size: 20rpx;
							color: #0291FF;
							// line-height: 96rpx;
							margin: 10rpx 12rpx 0 0;
						}
					}
				}
			}
		}

		.new-user {
			border-top: 20rpx solid #EFEFEF;
		}



		.bottom-btn {
			width: 100%;
			height: calc(136rpx + constant(safe-area-inset-bottom));
			height: calc(136rpx + env(safe-area-inset-bottom));

			.b-btn {
				position: fixed;
				bottom: 0;
				left: 0;
				right: 0;
				width: 100%;
				padding-bottom: constant(safe-area-inset-bottom);
				padding-bottom: env(safe-area-inset-bottom);

				.b {
					padding: 20rpx 22rpx;
					box-sizing: border-box;

					button {
						height: 96rpx;
						background: linear-gradient(132deg, #FFA233 0%, #FB4C4C 100%);
						border-radius: 48rpx 48rpx 48rpx 48rpx;
						font-weight: bold;
						font-size: 36rpx;
						color: #FFFFFF;
						line-height: 96rpx;
					}
				}
			}
		}
	}
	
	.active {
		background-color: #FFEEEE !important;
	}
</style>